/*
 * Status.java
 *
 * Created on 13 ������ 2007 �., 19:13
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

// #sijapp cond.if protocols_ICQ is "true" #
package org.jimm.protocol.icq;

import org.jimm.comm.*;

/**
 * @author aspro
 */
public final class Client {

    public static final byte CAPF_NO_INTERNAL = 0x00000000;
    // Client unterstands type-2 messages
    //public static final byte CAPF_AIM_SERVERRELAY = 0x00000001;
    // Client unterstands UTF-8 messages
    public static final byte CAPF_UTF8_INTERNAL = 0x00000002;
    //public static final byte CAPF_TYPING      = 0x00000004;
    //public static final byte CAPF_XTRAZ       = 0x00000008;
    public static final byte CAPF_DELIVERY = 0x00000010;

    // extended
    public static final int CAPF_AIMFILE = 0x00000020;
    public static final int CAPF_AVATAR = 0x00000040;
    public static final int CAPF_RICHTEXT = 0x00000080;
    public static final int CAPF_AIMICON = 0x00000100;
    public static final int CAPF_DIRECT = 0x00000200;

    public static final Client noneClient = new Client();

    public void reset() {
        caps = 0;
    }

    private byte caps = 0;
    // #sijapp cond.if modules_CLIENTS is "true" #
    public static final byte CLI_NONE = 0;
    private byte clientIndex = CLI_NONE;
    private String version = "";

    public int getClientIndex() {
        return ((int) clientIndex) & 0xFF;
    }

    public void setClient(int clientNum, String ver) {
        //       if (!ClientDetector.instance.has(clientNum)) {
        clientNum = CLI_NONE;
        ver = null;
        //       }
        clientIndex = (byte) clientNum;
        version = StringConvertor.notNull(ver);
    }
    // #sijapp cond.end #

    public Client() {
    }

    // #sijapp cond.if modules_CLIENTS is "true" #
    public int getIcon() {
        //return ClientDetector.instance.getClientIcon(getClientIndex());
        return 0;
    }

    public String getName() {
//        return ClientDetector.instance.getClient(getClientIndex());
        return "not supported";
    }

    public String getFullName() {
        if (CLI_NONE == clientIndex) {
            return null;
        }
        return getName() + " " + version;
    }

    public int getCaps() {
        return caps;
    }
    // #sijapp cond.end #

    public void setCapabilities(byte[] capabilities, int protocolVersion) {
        caps = Client.CAPF_NO_INTERNAL;
//        if (GUID.CAP_MTN.equals(capabilities)) {
//            caps |= Client.CAPF_TYPING;
//        }
//        if (GUID.CAP_XTRAZ.equals(capabilities)) {
//            caps |= Client.CAPF_XTRAZ;
//        }
        boolean full = GUID.CAP_AIM_SERVERRELAY.equals(capabilities);
        if (GUID.CAP_UTF8.equals(capabilities)) {
            caps |= Client.CAPF_UTF8_INTERNAL;
        }
        if ((protocolVersion > 8) && full) {
            caps |= CAPF_DELIVERY;
        }
    }

    public boolean hasCapability(int capability) {
        return (capability & caps) != 0x00000000;
    }
}

// #sijapp cond.end #
